home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_09_06 / 9n06044a < prev    next >
Text File  |  1991-02-27  |  3KB  |  74 lines

  1. /*   Listing 2  (RDSCRNC.C)
  2.                 APL to C functions
  3. */
  4.  
  5. struct screen_block            /* structure of argument passed from APL */
  6.  { short start_row;            /* will be passed as either a vector of  */
  7.    short start_col;            /* length 4 or an N,4 matrix.            */
  8.    short number_rows;
  9.    short number_cols;
  10.  };
  11.  
  12. void result_size(int,struct screen_block far *,short far *,short far *);
  13. void read_screen_blocks(short,struct screen_block far *,short,char far *);
  14.  
  15. /*
  16.      RESULT_SIZE - calculate size of APL Result.
  17.                    Equals number of rows in all blocks by
  18.                    the length of the longest row ..
  19. */
  20. void result_size(cnt,blocks,result_rows,result_cols)
  21. int cnt;                            /* number of rows in APL data */
  22. struct screen_block far * blocks;         /* the APL argument itself .. */
  23. short far * result_rows;                  /* # of rows in APL result    */
  24. short far * result_cols;                  /* # of cols in APL result .. */
  25. {
  26.    short i,temp_rows,temp_cols;
  27.  
  28.    temp_rows = 0;
  29.    temp_cols = 0;
  30.    for(i = 0;i < cnt;i ++)
  31.     { temp_rows += blocks[i].number_rows;
  32.       temp_cols = (temp_cols > blocks[i].number_cols)
  33.                    ? temp_cols : blocks[i].number_cols;
  34.     }
  35.    *result_rows = temp_rows;
  36.    *result_cols = temp_cols;
  37. }
  38.  
  39. /*
  40.      READ_SCREEN_BLOCKS - Read data from screen, fill in
  41.                           APL result ...
  42. */
  43. void read_screen_blocks(cnt,blocks,result_cols,result)
  44. short cnt;                                /* number of rows in APL arg  */
  45. struct screen_block far * blocks;         /* the APL argument itself .. */
  46. short result_cols;                        /* max # cols in APL result . */
  47. char far * result;                        /* APL result to be filled in */
  48. {
  49.    short i,j,k;
  50.    unsigned long video_memory,rowstart,position;
  51.    char video_mode;
  52.  
  53.    video_mode = *(char far *) 0x00400049;       /* get video mode       */
  54.    if(video_mode == 7)                          /* ie, mono  ...        */
  55.       video_memory = 0xb0000000;
  56.    else
  57.       video_memory = 0xb8000000;
  58.  
  59.    for(i = 0;i < cnt;i ++)                      /* process screen block */
  60.     { rowstart = video_memory + (unsigned) blocks[i].start_row * 160;
  61.       rowstart += (unsigned) blocks[i].start_col * 2;
  62.       for(j = 0;j < blocks[i].number_rows; j++)     /* process each row */
  63.        { position = rowstart;
  64.          for(k = 0;k < blocks[i].number_cols;k ++)     /* process cols .*/
  65.           { *result++ = *(char far *)position;         /* get char ..   */
  66.             position += 2;                             /* skip attribute*/
  67.           }
  68.          for(;k < result_cols;k ++)             /* any filler needed .. */
  69.             *result++ = ' ';
  70.          rowstart += 160;                       /* to next screen row   */
  71.        }
  72.     }
  73. }
  74.